// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import store from './store'
import auth from './utils/auth'

Vue.config.productionTip = false
Vue.use(iView)

router.beforeEach((to, from, next) => {
  iView.LoadingBar.start();
  let is_login = auth()
  if (to.meta.requireAuth) {
      console.log('1')
    if (is_login) {
      next();
    } else {
      next({
        path: '/login'
      })
    }
  } else {
      console.log('2')
      next();
  }

});

router.afterEach(route => {
  iView.LoadingBar.finish();
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: {
    App
  }
})
